/**
 * 文件名：extJquery.js
 * 版本信息： v 1.0
 * 日期：2016年8月22日
 * Copyright 深圳市佰仟金融服务有限公司 2016
 * 版权所有
 */

/**
 * $.format("{0}B{1}", "A", "C") == ABC;
 * 格式化占位符字符串
 */
$.format = function (source, params) {
    if (arguments.length == 1)
        return function () {
            var args = $.makeArray(arguments);
            args.unshift(source);
            return $.format.apply(this, args);
        };
    if (params == null || params == undefined) {
        params = "";
    }
    if (arguments.length > 2 && params.constructor != Array) {
        params = $.makeArray(arguments).slice(1);
    }
    if (params.constructor != Array) {
        params = [params];
    }
    $.each(params, function (i, n) {
        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
    });
    return source;
};


//清空form选择
function clearForm(id) {
    var formObj = document.getElementById(id);
    if (formObj == undefined) {
        return;
    }
    for (var i = 0; i < formObj.elements.length; i++) {
        if (formObj.elements[i].type == "text") {
            formObj.elements[i].value = "";
        }
        else if (formObj.elements[i].type == "password") {
            formObj.elements[i].value = "";
        }
        else if (formObj.elements[i].type == "radio") {
            formObj.elements[i].checked = false;
        }
        else if (formObj.elements[i].type == "checkbox") {
            formObj.elements[i].checked = false;
        }
        else if (formObj.elements[i].type == "select-one") {
            formObj.elements[i].options[0].selected = true;
        }
        else if (formObj.elements[i].type == "select-multiple") {
            for (var j = 0; j < formObj.elements[i].options.length; j++) {
                formObj.elements[i].options[j].selected = false;
            }
        }
        else if (formObj.elements[i].type == "file") {
            var file = formObj.elements[i];
            if (file.outerHTML) {
                file.outerHTML = file.outerHTML;
            } else {
                file.value = ""; // FF(包括3.5)
            }
        }
        else if (formObj.elements[i].type == "textarea") {
            formObj.elements[i].value = "";
        }
    }
}
